package com.yonyou.sto.modules.ums.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonyou.sto.modules.ims.dto.ImsPartySelectParam;
import com.yonyou.sto.modules.ims.model.ImsParty;
import com.yonyou.sto.modules.ums.mapper.UmsNcOrgMapper;
import com.yonyou.sto.modules.ums.model.UmsNcOrg;
import com.yonyou.sto.modules.ums.service.UmsNcOrgService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UmsNcOrgServiceImpl extends ServiceImpl<UmsNcOrgMapper, UmsNcOrg> implements UmsNcOrgService {
    @Resource
    UmsNcOrgMapper umsNcOrgMapper;
    @Override
    public Page<UmsNcOrg> list(String keyword, Integer pageSize, Integer pageNum) {
        Page<UmsNcOrg> page = new Page<>(pageNum, pageSize);
        QueryWrapper<UmsNcOrg> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<UmsNcOrg> lambda = wrapper.lambda();
        lambda.eq(UmsNcOrg::getDr, 0);
        if (StrUtil.isNotEmpty(keyword)) {
            lambda.like(UmsNcOrg::getName, keyword);
        }
        lambda.orderByAsc(UmsNcOrg::getName);
        return page(page, wrapper);
    }

    @Override
    public UmsNcOrg getData(String code) {
        QueryWrapper<UmsNcOrg> wrapper = new QueryWrapper<>();
        wrapper.eq("code", code);
        return umsNcOrgMapper.selectOne(wrapper);
    }

    @Override
    public List<UmsNcOrg> getPartySelect() {
//        QueryWrapper<UmsNcOrg> wrapper = new QueryWrapper<>();
//        wrapper.lambda().eq(UmsNcOrg::getDr, 0);
//        List<UmsNcOrg> parties = list(wrapper);
//        List<ImsPartySelectParam> params = new ArrayList<>();
        List<UmsNcOrg> list = list(new LambdaQueryWrapper<UmsNcOrg>()
                .eq(UmsNcOrg::getDr, 0)
        );
//        parties.forEach(imsParty -> {
//            ImsPartySelectParam param = new ImsPartySelectParam();
//            param.setPartyId(imsParty.getId());
//            param.setPartyName(imsParty.getPartyName());
//            params.add(param);
//        });
        return list;
    }

}
